/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.pedagogue.core.message.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.OneToMany;
import org.letmeshare.pedagogue.core.entities.Person;

/**
 *
 * @author abin
 */
@Entity
@NamedNativeQueries({
        @NamedNativeQuery(name =MailBox.GET_USER_MAILBOX,query = "SELECT X FROM MailBox X WHERE X.user.uid=:uid" ),
        @NamedNativeQuery(name =MailBox.GET_RECIVED_MESSAGES,query = "SELECT X.recivedMessages FROM MailBox X WHERE X.user.uid=:uid" ),
        @NamedNativeQuery(name =MailBox.GET_DRAFT_MESSAGES,query = "SELECT X.draftMessages FROM MailBox X WHERE X.user.uid=:uid" ),
        @NamedNativeQuery(name =MailBox.GET_SEND_MESSAGES,query = "SELECT X.sendMessages FROM MailBox X WHERE X.user.uid=:uid" )})
public class MailBox implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String id;
    @ManyToOne
    private Person user;
    @OneToMany
    private List<Message> draftMessages;
    @OneToMany
    private List<Message> recivedMessages;
    @OneToMany
    private List<Message> sendMessages;
    

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MailBox)) {
            return false;
        }
        MailBox other = (MailBox) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.letmeshare.pedagogue.core.message.entities.MailBox[ id=" + id + " ]";
    }

    public Person getUser() {
        return user;
    }

    public void setUser(Person user) {
        this.user = user;
    }

    public List<Message> getDraftMessages() {
        
        return draftMessages;
    }
    public void addDraftMessage(Message message){
        if(draftMessages==null)
            draftMessages=new ArrayList<Message>();
        draftMessages.add(message);
    }

    public void setDraftMessages(List<Message> draftMessages) {
        this.draftMessages = draftMessages;
    }

    public List<Message> getRecivedMessages() {
        
        return recivedMessages;
    }
    public void addRecivedMessage(Message message){
        if(recivedMessages==null)
            recivedMessages=new ArrayList<Message>();
        recivedMessages.add(message);
    }

    public void setRecivedMessages(List<Message> recivedMessages) {
        this.recivedMessages = recivedMessages;
    }

    public List<Message> getSendMessages() {
        
        return sendMessages;
    }
    public void addSendMessage(Message message){
        if(sendMessages==null)
            sendMessages=new ArrayList<Message>();
        sendMessages.add(message);
    }

    public void setSendMessages(List<Message> sendMessages) {
        this.sendMessages = sendMessages;
    }
    public static final String GET_USER_MAILBOX="GET_USER_MAILBOX";
     public static final String GET_RECIVED_MESSAGES="GET_RECIVED_MESSGAES";
     public static final String GET_DRAFT_MESSAGES="GET_DRAFT_MESSAGES";
     public static final String GET_SEND_MESSAGES="GET_SEND_MESSAGES";
    
}
